//
// graph.cpp for  in /home/jousse_f//workspace/Math/203poisson
// 
// Made by florian jousseau
// Login   <jousse_f@epitech.net>
// 
// Started on  Tue Mar 20 17:31:07 2012 florian jousseau
// Last update Fri Mar 23 15:11:30 2012 florian jousseau
//

#include "graph.hh"
#include "convertTo.hpp"
#include "203poisson.hh"
#include <stdio.h>

void		aff_etape2(int n, double p, std::list<double> list)
{
  RenderWindow		screen;

  screen.Create(sf::VideoMode(900, 675, 32), "203Poisson Morel_t / Jousse_f");
  screen.SetFramerateLimit(60);

  Shape		carre;

  carre.AddPoint(52, 102, Color(255, 255, 255), Color(255,255,255));
  carre.AddPoint(850, 102, Color(255, 255, 255), Color(255,255,255));
  carre.AddPoint(850, 600, Color(255, 255, 255), Color(255,255,255));
  carre.AddPoint(52, 600, Color(255, 255, 255), Color(255,255,255));
  carre.EnableFill(false);
  carre.EnableOutline(true);
  carre.SetOutlineWidth(2);
  screen.Draw(carre);

  Font			font;
  String		text;
  if (!font.LoadFromFile("DS-DIGIB.TTF"))
    printf("ERREUR CHARGEMENT POLICE\n");
  text.SetFont(font);

  text.SetSize(60);
  text.SetColor(Color(255, 0, 0));
  text.SetText("Loi Binomial");
  int largeurTexte = text.GetRect().GetWidth();
  text.SetPosition(Vector2f((900 - largeurTexte) / 2, 10));
  screen.Draw(text);

  text.SetColor(Color(255, 255, 255));
  text.SetSize(20);
  text.SetPosition(Vector2f(30, 85));
  text.SetText("1");
  screen.Draw(text);
  text.SetPosition(Vector2f(30, 585));
  text.SetText("0");
  screen.Draw(text);
  text.SetPosition(Vector2f(40, 605));
  text.SetText("-1");
  screen.Draw(text);
  text.SetPosition(Vector2f(840, 605));
  text.SetText(toString(n + 1));
  screen.Draw(text);

  text.SetColor(Color(255, 255, 255));
  text.SetSize(30);
  std::string	mytext = "loi binominal avec comme parametre n = " + toString(n) + " et p = " + toString(p);
  text.SetText(mytext);
  text.SetPosition(Vector2f((900 - text.GetRect().GetWidth()) / 2, 625));
  screen.Draw(text);

  int		x = 50;
  int		inc = 800 / (n + 2);
  std::list<double>::iterator	it = list.begin();

  while (it != list.end())
    {
      Shape		trait;

      trait.AddPoint(0, 0, Color(0, 255, 0), Color(255,255,255));
      trait.AddPoint(2, 0, Color(0, 255, 0), Color(255,255,255));
      trait.AddPoint(2, (*it) * 500, Color(0, 255, 0), Color(255,255,255));
      trait.AddPoint(0, (*it) * 500, Color(0, 255, 0), Color(255,255,255));
      trait.SetPosition(Vector2f(x, 600 - (*it) * 500));
      trait.EnableFill(true);
      screen.Draw(trait);
      ++it;
      x += inc;
    }

  screen.Display();
  while (screen.IsOpened())
    {
      Event event;

      while (screen.GetEvent(event))
        {
	  switch (event.Type)
            {
	    case Event::Closed :
	      screen.Close();
	      break;
	    case Event::KeyPressed :
	      {
		switch (event.Key.Code)
		  {
		  case Key::Escape :
		    return ;
		    break;
		  default:
		    break;
		  }
	      }
	      break;
	    default:
	      break;
            }
        }
      screen.Display();
    }
}

void		aff_etape3(double Y, std::list<double> list)
{
  RenderWindow		screen;

  screen.Create(sf::VideoMode(900, 675, 32), "203Poisson Morel_t / Jousse_f");
  screen.SetFramerateLimit(60);

  Shape		carre;

  carre.AddPoint(50, 100, Color(0, 0, 0), Color(255,255,255));
  carre.AddPoint(850, 100, Color(0, 0, 0), Color(255
,255,255));
  carre.AddPoint(850, 600, Color(0, 0, 0), Color(255,255,255));
  carre.AddPoint(50, 600, Color(0, 0, 0), Color(255,255,255));
  carre.EnableFill(true);
  carre.EnableFill(false);
  carre.EnableOutline(true);
  carre.SetOutlineWidth(2);
  screen.Draw(carre);

  Font			font;
  String		text;
  if (!font.LoadFromFile("DS-DIGIB.TTF"))
    printf("ERREUR CHARGEMENT POLICE\n");
  text.SetFont(font);

  text.SetSize(60);
  text.SetColor(Color(0, 255, 0));
  text.SetText("Loi Poisson");
  int largeurTexte = text.GetRect().GetWidth();
  text.SetPosition(Vector2f((900 - largeurTexte) / 2, 10));
  screen.Draw(text);

  text.SetColor(Color(255, 255, 255));
  text.SetSize(20);
  text.SetPosition(Vector2f(30, 85));
  text.SetText("1");
  screen.Draw(text);
  text.SetPosition(Vector2f(30, 585));
  text.SetText("0");
  screen.Draw(text);
  text.SetPosition(Vector2f(40, 605));
  text.SetText("-1");
  screen.Draw(text);
  text.SetPosition(Vector2f(840, 605));
  text.SetText("100");
  screen.Draw(text);

  text.SetColor(Color(255, 255, 255));
  text.SetSize(30);
  std::string	mytext = "loi poisson avec comme parametre lambda = " + toString(Y);
  text.SetText(mytext);
  text.SetPosition(Vector2f((900 - text.GetRect().GetWidth()) / 2, 625));
  screen.Draw(text);

  int		x = 50;
  int		inc = 800 / 100;
  std::list<double>::iterator	it = list.begin();

  while (it != list.end())
    {
      Shape		trait;

      trait.AddPoint(0, 0, Color(255, 0, 0), Color(255,255,255));
      trait.AddPoint(2, 0, Color(255, 0, 0), Color(255,255,255));
      trait.AddPoint(2, (*it) * 500, Color(255, 0, 0), Color(255,255,255));
      trait.AddPoint(0, (*it) * 500, Color(255, 0, 0), Color(255,255,255));
      trait.SetPosition(Vector2f(x, 600 - (*it) * 500));
      trait.EnableFill(true);
      screen.Draw(trait);
      ++it;
      x += inc;
    }

  while (screen.IsOpened())
    {
      Event event;

      while (screen.GetEvent(event))
        {
	  switch (event.Type)
            {
	    case Event::Closed :
	      screen.Close();
	      break;
	    case Event::KeyPressed :
	      {
		switch (event.Key.Code)
		  {
		  case Key::Escape :
		    return ;
		    break;
		  default:
		    break;
		  }
	      }
	      break;
	    default:
	      break;
            }
        }
      screen.Display();
    }
}

void		aff_etape4()
{
  RenderWindow		screen;

  screen.Create(sf::VideoMode(900, 675, 32), "203Poisson Morel_t / Jousse_f");
  screen.SetFramerateLimit(60);

  Shape		carre;

  carre.AddPoint(50, 100, Color(0, 0, 0), Color(255,255,255));
  carre.AddPoint(850, 100, Color(0, 0, 0), Color(255
,255,255));
  carre.AddPoint(850, 600, Color(0, 0, 0), Color(255,255,255));
  carre.AddPoint(50, 600, Color(0, 0, 0), Color(255,255,255));

  carre.EnableFill(true);
  carre.EnableFill(false);
  carre.EnableOutline(true);
  carre.SetOutlineWidth(2);

  screen.Draw(carre);

  Font			font;
  String		text;
  if (!font.LoadFromFile("DS-DIGIB.TTF"))
    printf("ERREUR CHARGEMENT POLICE\n");
  text.SetFont(font);

  text.SetSize(60);
  text.SetColor(Color(0, 0, 255));
  text.SetText("Loi Poisson / loi Binominal");
  int largeurTexte = text.GetRect().GetWidth();
  text.SetPosition(Vector2f((900 - largeurTexte) / 2, 10));
  screen.Draw(text);

  text.SetColor(Color(255, 255, 255));
  text.SetSize(20);
  text.SetPosition(Vector2f(30, 85));
  text.SetText("1");
  screen.Draw(text);
  text.SetPosition(Vector2f(30, 585));
  text.SetText("0");
  screen.Draw(text);
  text.SetPosition(Vector2f(40, 605));
  text.SetText("-1");
  screen.Draw(text);
  text.SetPosition(Vector2f(840, 605));
  text.SetText("100");
  screen.Draw(text);

  text.SetColor(Color(255, 255, 255));
  text.SetSize(30);
  std::string	mytext1 = "loi poisson avec comme parametre lambda = 50";
  text.SetText(mytext1);
  text.SetPosition(Vector2f((900 - text.GetRect().GetWidth()) / 2, 605));
  screen.Draw(text);

  text.SetColor(Color(255, 255, 255));
  text.SetSize(30);
  std::string	mytext = "loi binominal avec comme parametre n = 100 et p = 0.5";
  text.SetText(mytext);
  text.SetPosition(Vector2f((900 - text.GetRect().GetWidth()) / 2, 633));
  screen.Draw(text);

  int		x = 50;
  int		inc = 800 / 100;
  std::list<double>		list2 = option_3(50);
  std::list<double>		list1 = option_2(100, 0.5);
  std::list<double>::iterator	it = list2.begin();

  while (it != list2.end())
    {
      Shape		trait;

      trait.AddPoint(0, 0, Color(255, 0, 0), Color(255,255,255));
      trait.AddPoint(2, 0, Color(255, 0, 0), Color(255,255,255));
      trait.AddPoint(2, (*it) * 500, Color(255, 0, 0), Color(255,255,255));
      trait.AddPoint(0, (*it) * 500, Color(255, 0, 0), Color(255,255,255));
      trait.SetPosition(Vector2f(x, 600 - (*it) * 500));
      trait.EnableFill(true);
      screen.Draw(trait);
      ++it;
      x += inc;
    }

  it = list1.begin();
  x = 52;
  while (it != list1.end())
    {
      Shape		trait;

      trait.AddPoint(0, 0, Color(0, 255, 0), Color(255,255,255));
      trait.AddPoint(2, 0, Color(0, 255, 0), Color(255,255,255));
      trait.AddPoint(2, (*it) * 500, Color(0, 255, 0), Color(255,255,255));
      trait.AddPoint(0, (*it) * 500, Color(0, 255, 0), Color(255,255,255));
      trait.SetPosition(Vector2f(x, 600 - (*it) * 500));
      trait.EnableFill(true);
      screen.Draw(trait);
      ++it;
      x += inc;
    }
  while (screen.IsOpened())
    {
      Event event;

      while (screen.GetEvent(event))
        {
	  switch (event.Type)
            {
	    case Event::Closed :
	      screen.Close();
	      break;
	    case Event::KeyPressed :
	      {
		switch (event.Key.Code)
		  {
		  case Key::Escape :
		    return ;
		    break;
		  default:
		    break;
		  }
	      }
	      break;
	    default:
	      break;
            }
        }
      screen.Display();
    }
}
